package flychess.rules.impl;

import flychess.data.GameMap;
import flychess.entity.Player;
import flychess.rules.GameRule;
import flychess.util.UserInput;

public class LuckyTurnRule implements GameRule {
    private final GameMap map;
    public LuckyTurnRule(GameMap map) {
        this.map = map;
    }

    /**
     *
     * @param player 当前玩家
     * @param rival 对手
     * @param position 玩家的位置
     * @return 选择一种运气后玩家的位置
     */
    @Override
    public int handleRule(Player player, Player rival, int position) {
        System.out.println("◆◇◆◇◆欢迎进入幸运轮盘◆◇◆◇◆\n\t\t请选择一种运气：\n\t\t1. 交换位置  2. 轰炸");
        System.out.println("=============================");
        int sel = UserInput.getInputNum(1, 2, player.getPlayerType());
        int pos = rival.getPlayerPos();
        if (sel == 1) { // 交换位置
            rival.setPlayerPos(position);
            position = pos;
        }
        else if (sel == 2) { // 轰炸  另一名玩家后退6步
            pos -= 6;
            pos = map.convertToLegal(pos);
            rival.setPlayerPos(pos);
        }
        return position;
    }
}
